home *** CD-ROM | disk | FTP | other *** search
/ Die Ultimative Software-P…i Collection 1996 & 1997 / Die Ultimative Software-Pakete CD-ROM fur Atari Collection 1996 & 1997.iso / i / internet / software / dlinksr / pktqueue.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-04-01  |  2.0 KB  |  95 lines

  1. /********************************************************************/
  2. /*                                                                    */
  3. /*    Packet driver for D-LINK DE600 ethernet controller                */
  4. /*                                                                    */
  5. /*    Copyleft by P. Mayer, 1993 TU-Vienna IAEE                        */
  6. /*    All rights reserved                                                */
  7. /*                                                                    */
  8. /********************************************************************/
  9.  
  10. #include "nicmem.h"
  11. #include "pktqueue.h"
  12. #include <tos.h>
  13.  
  14. #ifndef NULL
  15. #define NULL (void *)0L
  16. #endif
  17.  
  18. #define FALSE 0
  19. #define TRUE  1 
  20.  
  21. #define DEBUGPKT
  22. #define noDEBUG
  23.  
  24. extern long p_disint(void);
  25. extern long p_enabint(void);
  26.  
  27. #define Bconws(x) dpy = x;while(*dpy)(Bconout(2,*dpy++))
  28.  
  29. extern char str[80];
  30. extern char *dpy;
  31.  
  32. PKTPOOL *p_init(int npkt,PKTPOOL *p_pool,PKTBUF *p_buf)
  33. {
  34. register int i;
  35.  
  36.     if(!p_pool) return(NULL);
  37.     p_pool->p_get = p_pool->p_put = 0;
  38.     p_pool->p_nbuf = npkt;
  39.     for(i=0; i<npkt; i++)
  40.     {
  41.         p_pool->p_tab[i].p_occupied = FALSE;
  42.         p_pool->p_tab[i].p_pkt = p_buf+i;
  43.     }
  44.     return(p_pool);
  45. }
  46.  
  47. PKTBUF *ap_getpkt(u_short protocol, PKTPOOL *p_pool)
  48. {
  49. PKTBUF *pkt;
  50.     p_disint();
  51.     pkt=p_getpkt(protocol,p_pool);
  52.     p_enabint();
  53.     return(pkt);
  54. }
  55.  
  56. PKTBUF *p_getpkt(u_short protocol, PKTPOOL *p_pool)
  57. {
  58. register int i;
  59.  
  60.     if(!p_pool) return(NULL);
  61.     i = p_pool->p_get;
  62.     if(p_pool->p_tab[i].p_occupied) return(NULL);
  63.     p_pool->p_get++;
  64.     if(p_pool->p_get >= p_pool->p_nbuf) p_pool->p_get = 0;
  65.     p_pool->p_tab[i].p_occupied = protocol;
  66.     return(p_pool->p_tab[i].p_pkt);
  67. }
  68.  
  69. int ap_putpkt(PKTPOOL *p_pool,PKTBUF *pkt)
  70. {
  71. int r;
  72.     p_disint();
  73.     r=p_putpkt(p_pool,pkt);
  74.     p_enabint();
  75.     return(r);
  76. }
  77.  
  78. int p_putpkt(PKTPOOL *p_pool,PKTBUF *pkt)
  79. {
  80. register int i;
  81.  
  82.     if(!p_pool) return(FALSE);
  83.     i = p_pool->p_put;
  84.     if(!p_pool->p_tab[i].p_occupied)
  85.     {
  86.         Bconws("DLINKDRV: Packet already free\r");
  87.         return(FALSE);
  88.      }
  89.     p_pool->p_put++;
  90.     if(p_pool->p_put >= p_pool->p_nbuf) p_pool->p_put = 0;
  91.     p_pool->p_tab[i].p_pkt = pkt;
  92.     p_pool->p_tab[i].p_occupied = FALSE;
  93.     return(TRUE);
  94. }
  95.